package com.you.atlas.web.place.module.screen;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.china.fasttext.json.JSONObject;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.RateService;
import com.you.common.webx.AuthContext;

public class RateAdd {

    @Autowired
    private RateService         rateService;

    @Autowired
    private HttpServletResponse response;

    public void execute(@Param("placeId") Long placeId) throws IOException {
        
        response.addHeader("Cache-Control", "no-cache");
        response.setContentType("application/json");
        
        JSONObject json = new JSONObject();
        boolean result = false;
        PrintWriter out = response.getWriter();
       
        if (!AuthContext.getContext().isLogin()) {
            json.put("result", result);
            json.put("error", "needLogin");
            out.write(json.toString());
            return;
        }
        
        if (placeId == null) {
            json.put("result", result);
            json.put("error", "placeId is null");
            out.write(json.toString());
            return;
        }

        result = rateService.createRate(AuthContext.getContext().getMemberId(), placeId);
        json.put("result", result);
        out.write(json.toString());

    }
}
